//
//  LoginView.m
//  吃货·上海
//
//  Created by 濮亚军 on 15/11/26.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "LoginView.h"
@interface LoginView()

//顶部背景
@property(nonatomic, strong)UIImageView *topBgImageView;

//底部背景
@property(nonatomic, strong)UIView *bottomView;

//头像区
@property(nonatomic, strong)UIImageView *userIconImageView;

//用户名
@property(nonatomic, strong)UIView *loginNameBG;

@property(nonatomic, strong)UIImageView *loginNameImageView;

//密码
@property(nonatomic, strong)UIView *loginPWBG;

@property(nonatomic, strong)UIImageView *loginPWImageView;

@end
@implementation LoginView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = KMyColor;
        //设置顶部的背景
        CGFloat n = KScreenWidth / 375;
        CGFloat height = n * 200;
        self.topBgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, frame.size.height)];
        self.backgroundColor = kBarColor;
        //self.topBgImageView.image = [UIImage imageNamed:@"foodie"];
        //self.topBgImageView.backgroundColor = [UIColor redColor];
        [self addSubview:_topBgImageView];
        
        //底部背景
        self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, height / 3, KScreenWidth, frame.size.height - height / 2)];
        //self.bottomView.backgroundColor = [UIColor redColor];
        [self addSubview:_bottomView];
        
        
        //头像
        CGFloat iconX = KScreenWidth  / 8 * 3;
        self.userIconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(iconX, -50, KScreenWidth / 4, KScreenWidth / 4)];
        //self.iconImageView.backgroundColor = [UIColor redColor];
        self.userIconImageView.image = [UIImage imageNamed:@"textIcon.jpg"];
        self.userIconImageView.layer.masksToBounds = YES;
        [self.userIconImageView.layer setCornerRadius:KScreenWidth / 8];
        [self.bottomView addSubview:_userIconImageView];
        
        //用户名背景
        self.loginNameBG = [[UIView alloc]initWithFrame:CGRectMake(0, 100 - 50, KScreenWidth, 50 * n)];
        //self.loginNameBG.backgroundColor = [UIColor redColor];
        [self.bottomView addSubview:_loginNameBG];
        
        CGFloat x = (KScreenWidth - 275) / 2;
        //用户名label
        self.loginNameImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, 5, 80, 35)];
        self.loginNameImageView.layer.masksToBounds = YES;
        [self.loginNameImageView.layer setCornerRadius:8];
        self.loginNameImageView.image = [UIImage imageNamed:@"userName"];
        [self.loginNameBG addSubview:_loginNameImageView];
        
        //用户名textfield
        self.loginNameTF = [[UITextField alloc]initWithFrame:CGRectMake(x + 80 + 10 , 5, 175, 35)];
        //self.loginNameTF.borderStyle = UITextBorderStyleRoundedRect;
        self.loginNameTF.placeholder = @"请输入用户名";
        self.loginNameTF.clearsOnBeginEditing = YES;
        self.loginNameTF.textAlignment = NSTextAlignmentLeft;
        [self.loginNameTF.layer setCornerRadius:8];
        //[self.loginNameTF.layer setBorderWidth:1];
        self.loginNameTF.backgroundColor = [UIColor colorWithRed:(242 / 255.0) green:(218 / 255.0) blue:(174 / 255.0) alpha:0.5];
        [self.loginNameBG addSubview:_loginNameTF];
        
        //密码背景
        self.loginPWBG = [[UIView alloc]initWithFrame:CGRectMake(0, 100 + 50 - 50, KScreenWidth, 50 * n)];
        [self.bottomView addSubview:_loginPWBG];
        
        //密码label
        self.loginPWImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, 5, 80, 35)];
        self.loginPWImageView.layer.masksToBounds = YES;
        [self.loginPWImageView.layer setCornerRadius:8];
        self.loginPWImageView.image = [UIImage imageNamed:@"userPW"];
        [self.loginPWBG addSubview:_loginPWImageView];
        
        //密码textfield
        self.loginPWTF = [[UITextField alloc]initWithFrame:CGRectMake(x + 80 + 10, 5, 175, 35)];
        self.loginPWTF.placeholder = @"请输入密码";
        self.loginPWTF.textAlignment = NSTextAlignmentLeft;
        self.loginPWTF.clearsOnBeginEditing = YES;
        [self.loginPWTF.layer setCornerRadius:8];
        self.loginPWTF.backgroundColor = [UIColor colorWithRed:(242 / 255.0) green:(218 / 255.0) blue:(174 / 255.0) alpha:0.5];
        [self.loginPWBG addSubview:_loginPWTF];
        
        //登录View
        CGFloat loginViewX = (KScreenWidth - 200) / 2;
        self.loginImageView = [[UIImageView alloc]initWithFrame:CGRectMake(loginViewX, 100 + 50 + 50 + 20 - 50, 80, 40)];
        self.loginImageView.backgroundColor = [UIColor redColor];
        self.loginImageView.layer.masksToBounds = YES;
        [self.loginImageView.layer setCornerRadius:8];
        self.loginImageView.userInteractionEnabled = YES;
        self.loginImageView.image = [UIImage imageNamed:@"login"];
        [self.bottomView addSubview:_loginImageView];
        
        //取消登录
        self.cancleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(loginViewX + 120, 100 + 50 + 50 + 20 - 50, 80, 40)];
        self.cancleImageView.backgroundColor = [UIColor redColor];
        self.cancleImageView.layer.masksToBounds = YES;
        [self.cancleImageView.layer setCornerRadius:8];
        self.cancleImageView.userInteractionEnabled = YES;
        self.cancleImageView.image = [UIImage imageNamed:@"cancel"];
        [self.bottomView addSubview:_cancleImageView];
        
        //忘记密码
        self.forgetPWImageView = [[UIImageView alloc]initWithFrame:CGRectMake( (KScreenWidth - 100) / 2, 100 + 50 + 50 + 20, 100, 40)];
        self.forgetPWImageView.backgroundColor = [UIColor redColor];
        self.forgetPWImageView.layer.masksToBounds = YES;
        [self.forgetPWImageView.layer setCornerRadius:8];
        self.forgetPWImageView.userInteractionEnabled = YES;
        self.forgetPWImageView.image = [UIImage imageNamed:@"forgetPW"];
        [self.bottomView addSubview:_forgetPWImageView];
        
        
    }
    return self;
}

@end
